<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.9
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############



class JFX_Module_Blockstyle_Property_Properties extends JFX_Module_Blockstyle_Property_Base
{
	public $id = 'properties';
	public $cssName = 'properties';
	public $title = 'Properties';


	
	public function init(){
		

		$opacityWidget = new JFX_Module_Blockstyle_Widget_Slider($this);
		$opacityWidget->min = 0;
		$opacityWidget->max = 1;
		$opacityWidget->unit = '';
		$opacityWidget->step = 0.01;
		$opacityWidget->name = 'Opacity';
		$opacityWidget->value = 1;
		$opacityWidget->showUnits = false;
		$opacityWidget->instanceId = $this->instanceId.'-opacity';
		$this->widgets[] = $opacityWidget;

		$colorWidget = new JFX_Module_Blockstyle_Widget_Color($this);
		$colorWidget->value = '000000';
		$colorWidget->name = 'Colour';
		$colorWidget->instanceId = $this->instanceId.'-color';
		$this->widgets[] = $colorWidget;

		$height = new JFX_Module_Blockstyle_Widget_Slider($this);
		$height->name = 'Height';
		$height->unit = JFX_Module_Blockstyle_Widget_Slider::$UNIT_PIXEL;
		$height->min = 0;
		$height->max = 2000;
		$height->value = 100;
		$height->instanceId = $this->instanceId.'-height';
		$this->widgets[] = $height;

		$minHeight = new JFX_Module_Blockstyle_Widget_Slider($this);
		$minHeight->name = 'Min Height';
		$minHeight->unit = JFX_Module_Blockstyle_Widget_Slider::$UNIT_PIXEL;
		$minHeight->min = 0;
		$minHeight->max = 2000;
		$minHeight->value = 100;
		$minHeight->instanceId = $this->instanceId.'-minheight';
		$this->widgets[] = $minHeight;

		$maxHeight = new JFX_Module_Blockstyle_Widget_Slider($this);
		$maxHeight->name = 'Max Height';
		$maxHeight->unit = JFX_Module_Blockstyle_Widget_Slider::$UNIT_PIXEL;
		$maxHeight->min = 0;
		$maxHeight->max = 2000;
		$maxHeight->value = 100;
		$maxHeight->instanceId = $this->instanceId.'-maxheight';
		$this->widgets[] = $maxHeight;


		$width = new JFX_Module_Blockstyle_Widget_Slider($this);
		$width->name = 'Width';
		$width->unit = JFX_Module_Blockstyle_Widget_Slider::$UNIT_PERCENT;
		$width->min = 0;
		$width->max = 2440;
		$width->value = 100;
		$width->instanceId = $this->instanceId.'-width';
		$this->widgets[] = $width;

		$minWidth = new JFX_Module_Blockstyle_Widget_Slider($this);
		$minWidth->name = 'Min Width';
		$minWidth->unit = JFX_Module_Blockstyle_Widget_Slider::$UNIT_PERCENT;
		$minWidth->min = 0;
		$minWidth->max = 2440;
		$minWidth->value = 100;
		$minWidth->instanceId = $this->instanceId.'-minwidth';
		$this->widgets[] = $minWidth;

		$maxWidth = new JFX_Module_Blockstyle_Widget_Slider($this);
		$maxWidth->name = 'Max Width';
		$maxWidth->unit = JFX_Module_Blockstyle_Widget_Slider::$UNIT_PERCENT;
		$maxWidth->min = 0;
		$maxWidth->max = 2440;
		$maxWidth->value = 100;
		$maxWidth->instanceId = $this->instanceId.'-maxwidth';
		$this->widgets[] = $maxWidth;



		$decorationWidget = new JFX_Module_Blockstyle_Widget_Multi($this);
		$decorationWidget->instanceId = $this->instanceId.'-textdecoration';
		$decorationWidget->name = 'Text Decoration';
		$decorationWidget->addOption('Overline', 'overline');
		$decorationWidget->addOption('Line Through', 'line-through');
		$decorationWidget->addOption('Underline', 'underline');
		$decorationWidget->addOption('Blink', 'blink');
		$decorationWidget->addOption('None', 'none');

		$decorationWidget->multiple = false;
		$decorationWidget->cssName = 'text-decoration';
		$decorationWidget->values[] = 'none';
		$this->widgets[] = $decorationWidget;



		$floatWidget = new JFX_Module_Blockstyle_Widget_Multi($this);
		$floatWidget->instanceId = $this->instanceId.'-float';
		$floatWidget->name = 'Float';
		$floatWidget->addOption('None', 'none');
		$floatWidget->addOption('Left', 'left');
		$floatWidget->addOption('Right', 'right');
		$floatWidget->multiple = false;
		$floatWidget->cssName = 'float';
		$floatWidget->values[] = 'none';
		$this->widgets[] = $floatWidget;


		$clearWidget = new JFX_Module_Blockstyle_Widget_Multi($this);
		$clearWidget->instanceId = $this->instanceId.'-clear';
		$clearWidget->name = 'Clear';
		$clearWidget->addOption('None', 'none');
		$clearWidget->addOption('Left', 'left');
		$clearWidget->addOption('Right', 'right');
		$clearWidget->multiple = false;
		$clearWidget->cssName = 'float';
		$clearWidget->values[] = 'none';
		$this->widgets[] = $clearWidget;


		$textAlignWidget = new JFX_Module_Blockstyle_Widget_Multi($this);
		$textAlignWidget->instanceId = $this->instanceId.'-textalign';
		$textAlignWidget->name = 'Text Align';
		$textAlignWidget->addOption('None', 'none');
		$textAlignWidget->addOption('Left', 'left');
		$textAlignWidget->addOption('Right', 'right');
		$textAlignWidget->addOption('Centered', 'center');
		$textAlignWidget->addOption('Justified', 'justified');
		$textAlignWidget->addOption('Inherit', 'inherit');
		$textAlignWidget->multiple = false;
		$textAlignWidget->cssName = 'text-align';
		$textAlignWidget->values[] = 'none';
		$this->widgets[] = $textAlignWidget;


		$displayWidget = new JFX_Module_Blockstyle_Widget_Multi($this);
		$displayWidget->instanceId = $this->instanceId.'-display';
		$displayWidget->name = 'Display';
		$displayWidget->addOption('Block', 'block');
		$displayWidget->addOption('Inline', 'inline');
		$displayWidget->addOption('Inline-Block', 'inline-block');
		$displayWidget->addOption('Table', 'table');
		$displayWidget->addOption('Table-Row', 'table-row');
		$displayWidget->addOption('Table-Cell', 'table-cell');
		$displayWidget->multiple = false;
		$displayWidget->cssName = 'display';
		$displayWidget->values[] = 'block';
		$this->widgets[] = $displayWidget;


		$positionWidget = new JFX_Module_Blockstyle_Widget_Multi($this);
		$positionWidget->instanceId = $this->instanceId.'-position';
		$positionWidget->name = 'Position';
		$positionWidget->addOption('Absolute', 'absolute');
		$positionWidget->addOption('Relative', 'relative');
		$positionWidget->addOption('Fixed', 'fixed');
		$positionWidget->addOption('Static', 'static');
		$positionWidget->addOption('Inherit', 'inherit');
		$positionWidget->multiple = false;
		$positionWidget->cssName = 'position';
		$positionWidget->values[] = 'relative';
		$this->widgets[] = $positionWidget;


		$leftWidget = new JFX_Module_Blockstyle_Widget_Slider($this);
		$leftWidget->name = 'Left';
		$leftWidget->unit = JFX_Module_Blockstyle_Widget_Slider::$UNIT_PERCENT;
		$leftWidget->min = -50;
		$leftWidget->max = 2440;
		$leftWidget->value = 0;
		$leftWidget->units[2] = 'auto';
		$leftWidget->unitNames[2] = 'Auto';
		$leftWidget->units[3] = 'inherit';
		$leftWidget->unitNames[3] = 'Inherit';
		$leftWidget->instanceId = $this->instanceId.'-left';
		$this->widgets[] = $leftWidget;

		$rightWidget = new JFX_Module_Blockstyle_Widget_Slider($this);
		$rightWidget->name = 'Right';
		$rightWidget->unit = JFX_Module_Blockstyle_Widget_Slider::$UNIT_PERCENT;
		$rightWidget->min = -50;
		$rightWidget->max = 2440;
		$rightWidget->value = 0;
		$rightWidget->units[2] = 'auto';
		$rightWidget->unitNames[2] = 'Auto';
		$rightWidget->units[3] = 'inherit';
		$rightWidget->unitNames[3] = 'Inherit';
		$rightWidget->instanceId = $this->instanceId.'-right';
		$this->widgets[] = $rightWidget;
		
		$topWidget = new JFX_Module_Blockstyle_Widget_Slider($this);
		$topWidget->name = 'Top';
		$topWidget->unit = JFX_Module_Blockstyle_Widget_Slider::$UNIT_PERCENT;
		$topWidget->min = -50;
		$topWidget->max = 2440;
		$topWidget->value = 0;
		$topWidget->units[2] = 'auto';
		$topWidget->unitNames[2] = 'Auto';
		$topWidget->units[3] = 'inherit';
		$topWidget->unitNames[3] = 'Inherit';
		$topWidget->instanceId = $this->instanceId.'-top';
		$this->widgets[] = $topWidget;

		$bottomWidget = new JFX_Module_Blockstyle_Widget_Slider($this);
		$bottomWidget->name = 'Bottom';
		$bottomWidget->unit = JFX_Module_Blockstyle_Widget_Slider::$UNIT_PERCENT;
		$bottomWidget->min = -50;
		$bottomWidget->max = 2440;
		$bottomWidget->value = 0;
		$bottomWidget->units[2] = 'auto';
		$bottomWidget->unitNames[2] = 'Auto';
		$bottomWidget->units[3] = 'inherit';
		$bottomWidget->unitNames[3] = 'Inherit';
		$bottomWidget->instanceId = $this->instanceId.'-bottom';
		$this->widgets[] = $bottomWidget;

	}


	public function __toCss(){
		$outputString = '';

		if(!$this->hasEnabledWidget()){
			return $outputString;
		}

		if(!$this->hasEnabledWidget() || $this->cssName=='' || $this->cssName != $this->id){
			return '/*not enabled '.$this->cssName.'*/ '.$outputString;
		}


		$colorWidget = $this->getWidget($this->instanceId.'-color');
		$colorOutput = $colorWidget->value;
		if($colorWidget->enabled && trim($colorOutput)!=''){
			$outputString .= '	color: #'.$colorOutput.";\n";
		}

		$heightWidget = $this->getWidget($this->instanceId.'-height');
		$heightOutput = $heightWidget->getCssValue();
		if($heightWidget->enabled && trim($heightOutput)!=''){
			$outputString .= '	height: '.$heightOutput.";\n";
		}

		$minHeightWidget = $this->getWidget($this->instanceId.'-minheight');
		$minHeightOutput = $minHeightWidget->getCssValue();
		if($minHeightWidget->enabled && trim($minHeightOutput)!=''){
			$outputString .= '	min-height: '.$minHeightOutput.";\n";
		}

		$maxHeightWidget = $this->getWidget($this->instanceId.'-maxheight');
		$maxHeightOutput = $maxHeightWidget->getCssValue();
		if($maxHeightWidget->enabled && trim($maxHeightOutput)!=''){
			$outputString .= '	max-height: '.$maxHeightOutput.";\n";
		}


		$widthWidget = $this->getWidget($this->instanceId.'-width');
		$widthOutput = $widthWidget->getCssValue();
		if($widthWidget->enabled && trim($widthOutput)!=''){
			$outputString .= '	width: '.$widthOutput.";\n";
		}

		$minWidthWidget = $this->getWidget($this->instanceId.'-minwidth');
		$minWidthOutput = $minWidthWidget->getCssValue();
		if($minWidthWidget->enabled && trim($minWidthOutput)!=''){
			$outputString .= '	min-width: '.$minWidthOutput.";\n";
		}

		$maxWidthWidget = $this->getWidget($this->instanceId.'-maxwidth');
		$maxWidthOutput = $maxWidthWidget->getCssValue();
		if($maxWidthWidget->enabled && trim($maxWidthOutput)!=''){
			$outputString .= '	max-width: '.$maxWidthOutput.";\n";
		}

		$textDecorationWidget = $this->getWidget($this->instanceId.'-textdecoration');
		$textDecorationOutput = $textDecorationWidget->getCssValue();
		if($textDecorationWidget->enabled && trim($textDecorationWidget)!=''){
			$outputString .= '	text-decoration: '.$textDecorationOutput.";\n";
		}



		$opacityWidget = $this->getWidget($this->instanceId.'-opacity');
		if($opacityWidget->enabled){
			$opacity = $opacityWidget->value;

			$outputString .= '	opacity : '.$opacity.';
	filter : alpha(opacity='.($opacity*100).');
';
			
		}
		
		$floatWidget = $this->getWidget($this->instanceId.'-float');
		if($floatWidget->enabled>0){
			$outputString .= '	float : '.$floatWidget->values[0].";\n";
		}

		$textAlignWidget = $this->getWidget($this->instanceId.'-textalign');
		if($textAlignWidget->enabled>0){
			$outputString .= '	text-align : '.$textAlignWidget->values[0].";\n";
		}

		$displayWidget = $this->getWidget($this->instanceId.'-display');
		if($displayWidget->enabled>0){
			$outputString .= '	display : '.$displayWidget->values[0].";\n";
		}

		$clearWidget = $this->getWidget($this->instanceId.'-clear');
		if($clearWidget->enabled>0){
			$outputString .= '	clear : '.$clearWidget->values[0].";\n";
		}

		$positionWidget = $this->getWidget($this->instanceId.'-position');
		if($positionWidget->enabled>0){
			$outputString .= '	position : '.$positionWidget->values[0].";\n";
		}

		$leftWidget = $this->getWidget($this->instanceId.'-left');
		if($leftWidget->enabled>0){
			if($leftWidget->unit=='auto'){
				$outputString .= '	left : auto;'."\n";
			}else if($leftWidget->unit=='inherit'){
				$outputString .= '	left : inherit;'."\n";
			}else{
				$outputString .= '	left : '.$leftWidget->value.$leftWidget->unit.";\n";
			}
		}

		$rightWidget = $this->getWidget($this->instanceId.'-right');
		if($rightWidget->enabled>0){
			if($rightWidget->unit=='auto'){
				$outputString .= '	right : auto;'."\n";
			}else if($rightWidget->unit=='inherit'){
				$outputString .= '	right : inherit;'."\n";
			}else{
				$outputString .= '	right : '.$rightWidget->value.$rightWidget->unit.";\n";
			}
		}

		$topWidget = $this->getWidget($this->instanceId.'-top');
		if($topWidget->enabled>0){
			if($topWidget->unit=='auto'){
				$outputString .= '	top : auto;'."\n";
			}else if($topWidget->unit=='inherit'){
				$outputString .= '	top : inherit;'."\n";
			}else{
				$outputString .= '	top : '.$topWidget->value.$topWidget->unit.";\n";
			}
		}

		$bottomWidget = $this->getWidget($this->instanceId.'-bottom');
		if($bottomWidget->enabled>0){
			if($bottomWidget->unit=='auto'){
				$outputString .= '	bottom : auto;'."\n";
			}else if($bottomWidget->unit=='inherit'){
				$outputString .= '	bottom : inherit;'."\n";
			}else{
				$outputString .= '	bottom : '.$bottomWidget->value.$bottomWidget->unit.";\n";
			}
		}

		return $outputString;
	}



}

